package jubaozhu.controller.admin;

import com.github.pagehelper.PageInfo;
import jubaozhu.domain.Orders;
import jubaozhu.extra.base.AdminBaseController;
import jubaozhu.extra.pojo.OrderPo;
import jubaozhu.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import zhibi.frame.domain.Page;
import zhibi.frame.mybatis.example.Example;
import zhibi.frame.mybatis.example.ExampleType;

import java.util.Date;

@Controller
@RequestMapping("/admin/order")
public class AdminOrderController extends AdminBaseController {

    @Autowired
    private OrdersService ordersService;

    @RequestMapping("list")
    public String list(Model model, Page page, OrderPo orderPo, String starttime, String endtime) {
        Example example = Example.getInstance()
                .addParam("o.id", orderPo.getId(), ExampleType.Operation.LIKE)
                .addParam("u.phone", orderPo.getPhone(), ExampleType.Operation.LIKE)
                .addParam("o.addtime", starttime, ExampleType.Operation.GTE)
                .addParam("o.addtime", endtime, ExampleType.Operation.LTE)
                .addParam("o.status", orderPo.getStatus())
                .addOrder("o.addtime", ExampleType.OrderType.DESC);
        PageInfo<OrderPo> pageInfo = ordersService.selectPoByExample(example, page);
        setModelAttribute(model, pageInfo);
        return "admin/order/list";
    }

    @PostMapping("verify")
    public String verify(Orders orders) {
        orders.setVerifytime(new Date());
        orders.setVerifyuser(sessionAdmin().getId());
        ordersService.updateByPrimaryKeySelective(orders);
        return refresh();
    }


}
